home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Files / Locations / FileLocation.h < prev    next >
Text File  |  2000-06-23  |  4KB  |  127 lines

  1. // FileLocation.h
  2.  
  3. #ifndef FileLocation_h
  4. #define FileLocation_h
  5.  
  6. #ifndef Volume_h
  7. #include "Volume.h"
  8. #endif
  9. #ifndef DirectoryID_h
  10. #include "DirectoryID.h"
  11. #endif
  12. #ifndef ConstPString_h
  13. #include "ConstPString.h"
  14. #endif
  15. #ifndef FileType_h
  16. #include "FileType.h"
  17. #endif
  18. #ifndef FileSignature_h
  19. #include "FileSignature.h"
  20. #endif
  21. #ifndef ScriptID_h
  22. #include "ScriptID.h"
  23. #endif
  24. #ifndef FileID_h
  25. #include "FileID.h"
  26. #endif
  27. #ifndef Directory_h
  28. #include "Directory.h"
  29. #endif
  30.  
  31. class PString;
  32. class CatInfo;
  33.  
  34. class FileLocation: public FSSpec
  35.   {
  36.     public:
  37.         FileLocation();
  38.         FileLocation( const FSSpec& source )    : FSSpec( source )        {}
  39.  
  40.         FileLocation( Directory );
  41.         FileLocation( Directory, ConstPString );
  42.         
  43.         ::Volume Volume() const                                { return ::Volume( vRefNum ); }
  44.         DirectoryID ParentID() const                        { return DirectoryID( parID ); }
  45.         Directory Parent() const                            { return Directory( Volume(), ParentID() ); }
  46.         ConstPString Name() const                            { return name; }
  47.         
  48.         void Set( Directory, ConstPString );
  49.         void operator=( Directory );
  50.         
  51.         void SetVolume( ::Volume v )                        { vRefNum = v.RefNum(); };
  52.         void SetParentID( DirectoryID d )                { parID = d.Number(); };
  53.         void SetParent( Directory d )                        { vRefNum = d.Volume().RefNum(); parID = d.ID().Number(); };
  54.         void SetName( ConstPString );
  55.         void SetName( ConstPString, uint32 );
  56.         
  57.         bool NameIsValid() const;
  58.         void SetToValidName( ConstPString );
  59.         void SetToValidName();
  60.  
  61.         bool IsRoot() const                                    { return ParentID() == DirectoryID::AboveRoot(); }
  62.         
  63.         FileLocation Child( ConstPString ) const;
  64.         FileLocation Sibling( ConstPString ) const;
  65.         
  66.         void Up();
  67.         void Down( ConstPString );
  68.         void Sideways( ConstPString );
  69.  
  70.         Directory AsDirectory() const;
  71.         
  72.         bool Exists() const;
  73.         void FindUnusedName();
  74.         
  75.         DirectoryID GetDirectoryID() const;
  76.         FileID GetFileID() const;
  77.  
  78.         static void ThrowError( OSErr );
  79.   };
  80.  
  81. bool operator==( const FileLocation&, const FileLocation& );
  82. inline bool operator!=( const FileLocation& a, const FileLocation& b )        { return !(a == b); }
  83.  
  84.  
  85. // These functions assume you know what's out there.
  86. // They throw if a source parameter does not exist,
  87. //            if a source parameter is the wrong type,
  88. //            or if a destination parameter exists.
  89. // This narrow license makes then safer to use.
  90.  
  91.     void CreateFile( const FileLocation& destination, FileType,                ScriptID script = ScriptID( smSystemScript ) );
  92.     void CreateFile( const FileLocation& destination, FileType, FileSignature, ScriptID script = ScriptID( smSystemScript ) );
  93.     
  94.     Directory CreateDirectory( const FileLocation& destination, ScriptID script = ScriptID( smSystemScript ) );
  95.         
  96.     void DeleteDirectory( const FileLocation& source );
  97.     void DeleteFile( const FileLocation& source );
  98.  
  99.     void LockFile( const FileLocation& source );
  100.     void UnlockFile( const FileLocation& source );
  101.  
  102.     void MoveFile( const FileLocation& source, const FileLocation& destination );
  103.     void CopyFile( const FileLocation& source, const FileLocation& destination );    // in CopyFile.cp
  104.     
  105.     void SwapFiles( const FileLocation& source1, const FileLocation& source2 );
  106.  
  107. // These do the same things, but can avoid duplicating a GetCatInfo call.
  108.     void DeleteDirectory( const CatInfo& source );
  109.     void DeleteFile( const CatInfo& source );
  110.     void MoveFile( const CatInfo& source, const FileLocation& destination );
  111.     void CopyFile( const CatInfo& source, const FileLocation& destination );    // in CopyFile.cp
  112.  
  113. // These functions are for when you want to get your way.
  114. // They may delete destination files or directories, or create
  115. // empty destination directories.
  116.  
  117.     void ForceDirectoryExistence( const FileLocation& destination );
  118.     
  119.     void ForceNonexistence( const FileLocation& source );
  120.     
  121.     void ForceMoveFile( const FileLocation& source, const FileLocation& destination );
  122.     void ForceCopyFile( const FileLocation& source, const FileLocation& destination );
  123.  
  124. void DeleteRecursively( const FileLocation& );
  125.  
  126. #endif
  127.